package cn.shujuhai.qtadmin.platform.kit;

import java.io.File;
import java.util.List;

import org.jetbrains.annotations.NotNull;
import org.springframework.mail.javamail.JavaMailSender;

import cn.shujuhai.qtadmin.platform.service.impl.SendEmailServiceImpl;
import lombok.SneakyThrows;

/**
 * EmailUtils
 *
 * @author dch798
 * @date 2021/10/15 20:54
 **/
@SuppressWarnings("ALL")
public class EmailUtils {

    private final JavaMailSender mailSender;

    public EmailUtils(JavaMailSender mailSender) {
        this.mailSender = mailSender;
    }

    /**
     *
     * @param from
     *            from
     * @param to
     *            to
     * @param cc
     *            cc
     * @param subject
     *            subject
     * @param text
     *            text
     */
    public void sendSimpleMail(String from, String to, String cc, String subject, String text) {
        SendEmailServiceImpl.mailInfo(from, to, cc, subject, text, mailSender);
    }

    /**
     *
     * @param from
     *            from
     * @param to
     *            to
     * @param cc
     *            cc
     * @param subject
     *            subject
     * @param text
     *            text
     * @param attachments
     *            attachments
     */
    @SneakyThrows
    public void sendAttachmentMail(String from, @NotNull String to, String cc, String subject, String text,
        List<File> attachments) {
        SendEmailServiceImpl.sendMailFiles(from, to, cc, subject, text, attachments, mailSender);
    }

    /**
     *
     * @param from
     *            from
     * @param to
     *            to
     * @param cc
     *            cc
     * @param subject
     *            subject
     * @param text
     *            text
     * @param file
     *            file
     */
    @SneakyThrows
    public void sendAttachmentMail(String from, @NotNull String to, String cc, String subject, String text, File file) {
        SendEmailServiceImpl.sendAttachmail(from, to, cc, subject, text, file, mailSender);
    }
}
